package com.anlu.paypal.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class PayPalSubmit {

    private static final Logger logger = LoggerFactory.getLogger(PayPalSubmit.class);

    public static String buildRequest(Map<String,String> sParaTemp, String linkUrl, String strMethod, String strButtonName) {
//        Map<String, String> sPara = buildRequestPara(sParaTemp);
        Map<String, String> sPara = sParaTemp;
        List<String> keys = new ArrayList(sPara.keySet());
        StringBuffer sbHtml = new StringBuffer();
        sbHtml.append("<form id=\"paypalsubmit\" name=\"paypalsubmit\" action=\""+ linkUrl + "\" method=\"" + strMethod + "\">");
        for(int i = 0; i < keys.size(); ++i) {
            String name = (String)keys.get(i);
            String value = (String)sPara.get(name);
            sbHtml.append("<input type=\"hidden\" name=\"" + name + "\" value=\"" + value + "\"/>");
        }
        sbHtml.append("<input type=\"submit\" value=\"" + strButtonName + "\" style=\"display:none;\"></form>");
        sbHtml.append("<script>document.forms['paypalsubmit'].submit();</script>");
        logger.debug("表单信息:"+sbHtml.toString());
        return sbHtml.toString();
    }

//    private static Map<String,String> buildRequestPara(Map<String,String> sParaTemp) {
//        Map<String, String> sPara = AlipayCore.paraFilter(sParaTemp);
//        return sPara;
//    }

}
